package com.libgdxbar.pvzlikegame.objects;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.libgdxbar.pvzlikegame.entities.MoveEntity;

import org.libgdxbar.projects.interfaces.renderer.ShapeRenderable;

// 最简示例 僵尸类
// 继承 MoveEntity 即可移动实体
// 实现 ShapeRenderable 接口 使用 ShapeRenderer 渲染图形
public class BaseZombie extends MoveEntity implements ShapeRenderable {
    public BaseZombie(float x, float y) {
        // 演示逻辑 创建随机方向移动的僵尸
        super(x, y, MathUtils.random(200f) + 200f, MathUtils.random(200f) + 200f);
    }

    // 实现渲染方法
    @Override
    public void render(ShapeRenderer renderer) {
        Vector2 position = getPosition();
        renderer.setColor(Color.RED);
        renderer.rect(position.x, position.y, 50, 50);
    }

    // 实现僵尸逻辑
    @Override
    public void run(float delta) {
        super.run(delta);
        Vector2 position = getPosition();
        // 这里碰屏幕边缘反弹只是演示逻辑而已 实际请自己实现
        if (position.x > 640 - 50) setVelocityX(-Math.abs(getVelocityX()));
        if (position.x < 0) setVelocityX(Math.abs(getVelocityX()));
        if (position.y > 480 - 50) setVelocityY(-Math.abs(getVelocityY()));
        if (position.y < 0) setVelocityY(Math.abs(getVelocityY()));
    }
}
